import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class AtributeReader {

    /**
     * @param args
     */
    public static void main(String[] args) {
	try {
	    DocumentBuilderFactory factory = DocumentBuilderFactory
		    .newInstance();
	    DocumentBuilder builder = factory.newDocumentBuilder();

	    File f = new File("C:\\2.xml");
	    Document doc = builder.parse(f);

	    Element root = doc.getDocumentElement();

	    NamedNodeMap attributes = root.getAttributes();

	    if (attributes != null) {

		for (int j = 0; j < attributes.getLength(); j++) {
		    Node attribute = attributes.item(j);
		    String name = attribute.getNodeName();
		    String value = attribute.getNodeValue();
		    System.out.printf("%s %s\n", name, value);

		}
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	}
    }

}
